package bio.demo3;

import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.net.Socket;
import java.util.Scanner;

/**
 * @author charwayH
 * 目标:
 */
public class Client {
    public static void main(String[] args) {
        try {
            // 1.创建一个Socket对象请求服务端连接
        Socket socket = new Socket("127.0.0.1", 9997);
        // 2.让Socket对象中获取字节输出流
        OutputStream os = socket.getOutputStream();
        // 3.把字节输出流包装成打印流
        PrintStream ps = new PrintStream(os);
        Scanner scanner = new Scanner(System.in);
        while (true) {
            System.out.print("请输入消息内容");
            String msg = scanner.nextLine();
            ps.println(msg);
            ps.flush();
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    }
}